import java.util.Stack;

public class MinStack {
     //最小栈
    Stack<Integer> stack;//普通栈
    Stack<Integer> minStack;//最小栈

    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int val) {
        stack.push(val);
        if(minStack.empty()) {
            minStack.push(val);
        }else {
            int peekNum = minStack.peek();
            if(val <= peekNum) {
                minStack.push(val);
            }
        }
    }

    public void pop() {
        int peekNum1 = stack.pop();;
        int peekNum2 = minStack.peek();
        if(peekNum1 == peekNum2) {
            minStack.pop();
        }
    }
    //相当于peek()
    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}
